import HeldCharacterTalk_Generate from "../ui-generate/HeldCharacterTalk_generate";

export class CharacterTalk {
    private static target: Character;
    private static uiWight: UIWidget;
    private static txt_context: TextBlock;

    static show(target: Character, talk: string) {
        this.check();
        this.target = target;
        this.txt_context.text = talk;

        this.target.attachToSlot(this.uiWight, HumanoidSlotType.Root);
        this.uiWight.localTransform.position = new Vector(0, 0, 240);
        this.uiWight.setVisibility(true);
    }

    static hide() {
        this.uiWight.parent = undefined;
        this.uiWight.setVisibility(false);
    }

    private static check() {
        if (this.uiWight) return;

        this.uiWight = <UIWidget>GameObject.spawn('UIWidget');
        let uiContent = UIService.create(HeldCharacterTalk_Generate);
        this.uiWight.setTargetUIWidget(uiContent.uiObject as mw.UserWidget);
        this.txt_context = uiContent.txt_context;
        this.uiWight.widgetSpace = WidgetSpaceMode.OverheadUI;
    }
}
